﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogisticsBLL;
using System.Data.SqlClient;
using System.Text;
using System.Data;

namespace WebLosgic
{
    public partial class Users : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (Session["names"] != null)
                {
                    string ming = Session["names"].ToString();
                    Names.Text = ming;
                }
                droplist();
                chaxun();
                
            }
        }


        protected void chaxun()
        {
            string txtName = TextName.Text;
            string phone = TxtPhone.Text;
            string checktime = TxtchkTime.Text;
            string checkzhi = Textzhi.Text;
            string Tsex =RadioSex.SelectedValue;
            string delet = TxtDelete.Text;
            string afterTime = TxtAftertime.Text;
            string afterzhi = Textzhi2.Text;
            string acount = TxtAcount.Text;
            string Email = TxtEmail.Text;
            string roles = DDrole.SelectedValue;
            int pageindex = AspNetPagerTool.CurrentPageIndex;
            int pagesize = AspNetPagerTool.PageSize;
            int Recount = 0;
            UserBLL bll = new UserBLL();
            RptBindUser.DataSource = bll.UserSelet(txtName, phone, checktime, checkzhi,
            Tsex, delet, acount, Email, roles, afterTime, afterzhi,
            pageindex, pagesize, out Recount);
            AspNetPagerTool.RecordCount = Recount;
            RptBindUser.DataBind();
        }


        //下拉列表
        public void droplist()
        {

            SqlDataReader reader = LogBLL.ddrole();
            DDrole.DataSource = reader;
            DDrole.DataTextField = "RoleName";
            DDrole.DataValueField = "RoleName";
            DDrole.DataBind();
            DDrole.Items.Insert(0, new ListItem("--请选择--", "0"));
            
        }

        protected void RetrieveBut_Click(object sender, EventArgs e)
        {
            chaxun();
        }

        protected void ResetBut_Click(object sender, EventArgs e)
        {
            TextName.Text=" ";
            TxtPhone.Text="";
            TxtchkTime.Text="";
            Textzhi.Text="";
            RadioSex.SelectedValue="2";
            TxtDelete.Text="";
            TxtAftertime.Text="";
            Textzhi2.Text="";
            TxtAcount.Text="";
            TxtEmail.Text="";
            string roles = DDrole.SelectedValue;
        }



        protected void AspNetPagerTool_PageChanged(object sender, EventArgs e)
        {
            chaxun();
        }

        


   

        protected void LinkUpdate_Click(object sender, EventArgs e)
        {
            int UserID = Convert.ToInt32(((LinkButton)sender).CommandArgument);
            Response.Redirect("UpdateUser.aspx?Uid=" + UserID);
        }

        protected void LinkDelete_Click(object sender, EventArgs e)
        {
            int UserID = Convert.ToInt32(((LinkButton)sender).CommandArgument);
            int result = UserBLL.dels(UserID);
            string name = Session["names"].ToString();
            string Behavor = "" + name + ": 删除员工";
            int TypeId = 3;
            int UserIDs = Convert.ToInt32(Session["UserIDs"]);
            string Parameters = @"" + UserID + "";
            string ProcName = "p_del";
            HttpRequest request = HttpContext.Current.Request;
            string IP = "192.168.0.1";
            int IsExcePion = 0;
            if (result > 0)
            {
                IsExcePion = 0;
                int a = ProcBLL.InserSys(Behavor, TypeId, UserIDs, Parameters, ProcName, IP, IsExcePion);
                if (a > 0)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "error", "alert('删除成功')", true);
                }

            }
            else
            {
                IsExcePion = 1;
                int a = ProcBLL.InserSys(Behavor, TypeId, UserIDs, Parameters, ProcName, IP, IsExcePion);
                if (a > 0)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "error", "alert('删除失败')", true);
                }

            }
            chaxun();
        }
    }
}